package com.oba.king.hospitalinfo.hospitalinformation;

import com.oba.base.dao.BaseDao;
import com.oba.base.interfaces.IHsqlBuilder;

public class HospitalInformationDao extends BaseDao {
	
	public IHsqlBuilder buildAll(){
		IHsqlBuilder sql = this.getSqlBuilder("from HospitalInformation hosp"); 
		sql.addend("order by hosp.hospitalName");
		return sql;
	}
	
	public IHsqlBuilder srchByHospitalNm(String hospitalName){
		System.out.println("hospitalName = "+hospitalName);
		IHsqlBuilder sql = getSqlBuilder("from HospitalInformation hosp");
		sql.add("hosp.hospitalName like ?", hospitalName, "%", "%");
		sql.addend("order by hosp.hospitalName");
		return sql;
	}
	
	public IHsqlBuilder srchByHospitalCondition(HospitalCondition hospitalCondition){
//		System.out.println("hospitalName = "+hospitalCondition);
		IHsqlBuilder sql = getSqlBuilder("from HospitalInformation hosp");
		if(hospitalCondition.getHospitalName()!=null&& !hospitalCondition.getHospitalName().trim().equals("")){
			sql.add("hosp.hospitalName like ?", hospitalCondition.getHospitalName().trim(), "%", "%");			
		}
		if(hospitalCondition.getCityName()!=null&& !hospitalCondition.getCityName().trim().equals("")){
			sql.add("hosp.cityName =?", hospitalCondition.getCityName().trim());			
		}
		if(hospitalCondition.getHospitalCode()!=null && !hospitalCondition.getHospitalCode().trim().equals("")){
			sql.add("hosp.hospitalCode =?", hospitalCondition.getHospitalCode().trim());			
		}
		if(hospitalCondition.getHospitalGrade()!=null&& !hospitalCondition.getHospitalGrade().trim().equals("")){
			sql.add("hosp.hospitalGrade =?", hospitalCondition.getHospitalGrade().trim());			
		}
		if(hospitalCondition.getHospitalProperty()!=null&& !hospitalCondition.getHospitalProperty().trim().equals("")){
			sql.add("hosp.hospitalProperty =?", hospitalCondition.getHospitalProperty().trim());		
		}
		if(hospitalCondition.getDocumentId()!=null&& !hospitalCondition.getDocumentId().trim().equals("")){
			sql.add("hosp.documentId =?", hospitalCondition.getDocumentId().trim());			
		}
		sql.addend("order by hosp.hospitalName");
		return sql;
	}
}
